package com.swyc.osschat.Test.designMode.singleCase.run;

/**
 * @description 双重检查
 * 优点：线程安全，懒加载。
 * @Author: z156940l@outlook.com
 * @className SingleObj6
 * @Date: 2022/7/25 18:34
 */
public class SingleObj6 {
    //私有化构造方法，防止外部new
    private SingleObj6(){
    }

    //提供静态变量 volatile - 保证变量的内存可见性 - 禁止指令重排序
    private volatile static SingleObj6 instance;

    //返回实例
    public static SingleObj6 getInstance(){
        //进行两次判断
        if (instance==null){
            synchronized (SingleObj6.class){
                if (instance==null){
                    instance = new SingleObj6();
                }
            }
        }
        return instance;
    }
}
